package club.gskj.gulimall.search.controller;

/**
 * @ClassName SearchController
 * @Description TODO
 * @Author 康纳
 * @Date 2021-02-27
 */

import club.gskj.gulimall.search.service.IMallSearchService;
import club.gskj.gulimall.search.vo.SearchParamVo;
import club.gskj.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 关键字检索控制器
 */
@Controller
public class SearchController {

    @Autowired
    private IMallSearchService mallSearchService;

    /**
     * @param paramVo
     * @param model
     * @return java.lang.String
     * @author 康纳-connor
     * @creed: Talk is cheap,show me the code
     * @date 21.2.28 19:34
     * @Description 根据检索条件，返回前台商品信息
     */
    @RequestMapping("/list.html")
    public String listPage(SearchParamVo paramVo, Model model, HttpServletRequest request) {

        // 获取? 后面的param
        String queryString = request.getQueryString();
        paramVo.set_queryString(queryString);
        SearchResult result = mallSearchService.search(paramVo);
        model.addAttribute("result", result);
        return "list";
    }
}
